/**
 * Copyright (c) 2017-2024 Nop Platform. All rights reserved.
 * Author: canonical_entropy@163.com
 * Blog:   https://www.zhihu.com/people/canonical-entropy
 * Gitee:  https://gitee.com/canonical-entropy/nop-entropy
 * Github: https://github.com/entropy-cloud/nop-entropy
 */
package com.gitee.wsl.struct.table.impl

import com.gitee.wsl.struct.table.ICell
import com.gitee.wsl.struct.table.IRowView


abstract class AbstractCell : ICell {

    override var isFrozen: Boolean = false

    override var id: String? = null

    override var styleId: String? = null

    override var row: IRowView? = null
        set(row) {
            checkAllowChange()
            field = row
        }

    override var rowOffset: Int = 0

    override var colOffset: Int = 0

    override fun toString(): String {
        val sb = StringBuilder()
        sb.append("Cell[")
        if (id != null) sb.append("id=").append(id).append(",")
        sb.append("text=").append(text)
        if (this.mergeAcross > 0) sb.append(",colSpan=").append(colSpan)
        if (this.mergeDown > 0) sb.append(",rowSpan=").append(rowSpan)

        appendInfo(sb)
        sb.append("]")
        return sb.toString()
    }

    protected fun appendInfo(sb: StringBuilder) {}

    protected fun copyTo(cell: AbstractCell) {
        cell.id = id
    }

    /*fun getId(): String? {
        return id
    }

    fun setId(cellId: String?) {
        checkAllowChange()
        this.id = cellId
    }

    fun getStyleId(): String? {
        return styleId
    }

    fun setStyleId(styleId: String?) {
        checkAllowChange()
        this.styleId = styleId
    }*/


    /*protected fun outputJson(out: IJsonHandler) {
        super.outputJson(out)
        if (id != null) out.put("id", id)
        if (styleId != null) out.put("styleId", styleId)
    }

    companion object {
        private const val serialVersionUID = 1L
    }*/
}